package Io;

import java.io.*;
import java.util.Scanner;

/**
 * 复制文件
 */
public class IoDemo9 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入你要拷贝文件的源路径:");
        String srcPath = scanner.next();
        File file1 = new File(srcPath);
        if (!file1.isFile()) {
            System.out.println("没有你要复制的文件 或 输入的路径不合法!");
            return;
        }
        System.out.println("输入你要拷贝的目标路径:");
        String destPath = scanner.next();
        File file2 = new File(destPath);
        if (file2.isFile()) {
            System.out.println("复制的文件已存在 或 输入的路径不合法!");
            return;
        }
        try (InputStream inputStream = new FileInputStream(file1);
             OutputStream outputStream = new FileOutputStream(file2)){
                while (true) {
                    int res = inputStream.read();
                    if (res == -1) {
                        break;
                    }
                    outputStream.write(res);
                }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
